﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Controls_con_parameter : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int sid = int.Parse(Session["mid"].ToString());
        DBaccess db = new DBaccess();
        DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();
        DataSet ds3 = new DataSet();
        DataSet ds4 = new DataSet();
        DataSet ds5 = new DataSet();
        String sql1 = "select download_weight from mr_member where mid = '" + sid + "'";
        String sql2 = "select preference_weight from mr_member where mid = '" + sid + "'";
        String sql3 = "select time_weight from mr_member where mid = '" + sid + "'";
        String sql4 = "select difficulty_weight from mr_member where mid = '" + sid + "'";
        ds1 = db.GetDataSet(sql1);
        TextBoxDownload.Text = ds1.Tables[0].Rows[0][0].ToString();
        ds2 = db.GetDataSet(sql2);
        TextBoxPreference.Text = ds2.Tables[0].Rows[0][0].ToString();
        ds3 = db.GetDataSet(sql3);
        TextBoxTime.Text = ds3.Tables[0].Rows[0][0].ToString();
        ds4 = db.GetDataSet(sql4);
        TextBoxGPA.Text = ds4.Tables[0].Rows[0][0].ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String sid = Session["mid"].ToString();
        if (double.Parse(TextBoxDownload.Text) + double.Parse(TextBoxPreference.Text) + double.Parse(TextBoxTime.Text) + double.Parse(TextBoxGPA.Text) == 1)
        {
            DBaccess db = new DBaccess();
            String[] sql = new String[4];
            sql[0] = "update mr_member set download_weight = '" + TextBoxDownload.Text + "' where mid = '" + sid + "'";
            sql[1] = "update mr_member set preference_weight = '" + TextBoxPreference.Text + "' where mid = '" + sid + "'";
            sql[2] = "update mr_member set time_weight = '" + TextBoxTime.Text + "' where mid = '" + sid + "'";
            sql[3] = "update mr_member set difficulty_weight = '" + TextBoxGPA.Text + "'where mid = '" + sid + "'";
            db.ExecTranscation(sql);
            Response.Write("<script>alert('modify成功!');</script>");
        }
        else
            Response.Write("<script>alert('请确保各权值总和为100%');</script>");
    }
}